package com.ivan.hospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ivan.common.result.Result;
import com.ivan.model.entity.hosp.Department;
import com.ivan.model.entity.hosp.Hospital;
import com.ivan.hospital.service.HospitalService;
import com.ivan.model.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Ivan
 * @date 2021/3/13 18:48
 * @Description:
 */
@Api(tags = "医院管理接口")
//@CrossOrigin//使用gateway后做了配置
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "医院列表(条件查询分页)")
    @GetMapping("getHospList/{page}/{limit}")
    public Result getHospList(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           HospitalQueryVo hospitalQueryVo) {
       Page<Hospital> hospitalPage = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
       return Result.ok(hospitalPage);
    }

    @ApiOperation(value = "更新医院上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status) {
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }

    @ApiOperation(value = "根据医院的编号查询医院的详情")
    @GetMapping("showHospDetail/{hoscode}")
    public Result showHospDetail(@PathVariable String hoscode) {
        Map<String, Object> map = hospitalService.getHospByHoscode(hoscode);
        return Result.ok(map);
    }

    @ApiOperation(value = "通过医院名称查询信息")
    @GetMapping("findByHosname/{hosname}")
    public Result findByHosname(@PathVariable String hosname) {
        List<Hospital> hospitals = hospitalService.findByHosname(hosname);
        return Result.ok(hospitals);
    }

    @ApiOperation(value = "根据医院的编号查科室")
    @GetMapping("findDepartment/{hoscode}")
    public Result findDepartment(@PathVariable String hoscode) {
        List<Department> departments = hospitalService.findDepartment(hoscode);
        return Result.ok(departments);
    }
}
